package com.park.carpark.controller;


import com.park.carpark.pojo.Parking_Register;
import com.park.carpark.service.ParkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;


@Controller
@RequestMapping("/Park")
public class TestController {

    @Resource
    private ParkService parkService;


    //入库车辆信息显示
    @RequestMapping("/ListParkEnter")
    public String list(Model model){
        List<Parking_Register> parks = parkService.showParkMsg();
        model.addAttribute("list",parks);
        System.out.println("车库信息++++111111");
        return "ListPark";
    }

    //跳转到车辆登记页面
    @RequestMapping("/toEnter")
    public String toEnter(){
        return "enter";
    }

    //登记车辆入库信息
    @RequestMapping("/addPark")
    public String addPark(Parking_Register park){
        System.out.println("park-->"+park);
        parkService.addCarMsg(park);
        return "redirect:/Park/ListParkEnter";
    }

    //跳转到车辆出库登记页面
    @RequestMapping("/toOuter")
    public String toOuter(String id,Model model){
        Parking_Register park=parkService.showOutMsg(id);
        System.out.println(park.getCar_ID());
        System.out.println(park.getEnter_time());
        model.addAttribute("park",park);
        return "outer";
    }

    //登记车辆出库时间
    @RequestMapping("/outPark")
    public String outPark(Parking_Register park){
        System.out.println("update-->"+park);
        //增加出库信息（出库时间，停放时间）
        parkService.updateMsg(park);
        //增加出库信息 （应缴金额）
        parkService.updatePrice(park);
        System.out.println("噗噗噗"+park.getOut_time());
        return "redirect:/Park/ListParkEnter";
    }

    //退出系统
    @RequestMapping("/outSystem")
    public String outSystem(){
        return "outSystem";
    }

    //菜单主页
    @RequestMapping("/index")
    public String index(){
        return "index";
    }



}
